import DAL from './dal.js';
/**
 * 跟代码对照表相关的方法
 */
class CodeValueDal{
	constructor(){
		this.init();
	};
	
	init(){
		this.db = new DAL();
	};
	
/**
		 * @param {Object} 
		 * 按照数据项的编号和值来源编号来查询文字值
		 */
		async SelectCodeTextByColumeNameAndCodeValue(columeName,codeValue){
			let persionIDArrray = new Array();
			let rowArray = await this.db.readField('code_value','DISTINCT CODE_NAME',
												`WHERE
												CODE_COLUMN_NAME LIKE \'${columeName}%\' and CODE_VALUE=\'{codeValue}\' `).catch(error=>{
																					console.log(error);
																				});
			rowArray.forEach(function(item){
				persionIDArrray.push(item.CODE_NAME)
			});
			return persionIDArrray;
		}
		
		/**
		 * @param {Object} 
		 * 按照文字值和值来源编号来查询数据项的编号
		 */
		async SelectCodeValueByColumeNameAndCodeText(columeName,CodeText){
			let persionIDArrray = new Array();
			let rowArray = await this.db.readField('code_value','DISTINCT CODE_VALUE',
												`WHERE
												CODE_COLUMN_NAME LIKE \'${columeName}%\' and CODE_NAME=\'{CodeText}\' `).catch(error=>{
																					console.log(error);
																				});
			rowArray.forEach(function(item){
				persionIDArrray.push(item.CODE_VALUE)
			});
			return persionIDArrray;
		}
		
		/**
		 * @param {Object} CodeType
		 * @param {Object} CodeText
		 * 通过文本和数据类别查询对应的编号值
		 */
		async SelectCodeValueByCodeTypeAndCodeText(CodeType,CodeText){
			let persionIDArrray = new Array();
			let CodeValue = await this.db.readField('code_value','DISTINCT CODE_VALUE',
												`WHERE
												CODE_TYPE = \'{CodeType}\' and CODE_NAME=\'{CodeText}\' `).catch(error=>{
																					console.log(error);
																				});
			rowArray.forEach(function(item){
				persionIDArrray.push(item.CODE_VALUE)
			});
			return persionIDArrray;
		}
		
		/**
		 * @param {Object} CodeType
		 * @param {Object} CodeValue
		 * 通过编号值和数据类别查询对应的文本
		 */
		async SelectCodeTextByCodeTypeAndCodeValue(CodeType,CodeValue){
			let persionIDArrray = new Array();
			let rowArray = await this.db.readField('code_value','DISTINCT CODE_NAME',
												`WHERE
												CODE_TYPE = \'{CodeType}\' and CODE_VALUE=\'{CodeValue}\' `).catch(error=>{
																					console.log(error);
																				});
			rowArray.forEach(function(item){
				persionIDArrray.push(item.CODE_NAME)
			});
			return persionIDArrray;
		}
}

export default CodeValueDal;